package diagramobjects;

import java.awt.Graphics;
import java.util.ArrayList;

import utils.Point;
import utils.Color;

import program.PaintObjects;

public class BorderAreaUses extends DiagramObject
{
	private Text Name;
	private Point LeftUp;
	private Point LeftDown;
	private Point RightUp;
	private Point RightDown;
	
	
	
	
	
	
	public BorderAreaUses(Text name, Point lu, Point ld, Point ru,
			Point  rd) 
	{
		super();
		Name = name;
		LeftUp = lu;
		LeftDown = ld;
		RightUp = ru;
		RightDown = rd;
	}

	public BorderAreaUses(String name, Integer x, Integer y)
	{
		super();
		Name = new Text("Area", new Point(x, y), new Color(0,11,255), 10);
		LeftUp = new Point(x, y);
		LeftDown = new Point(x, y);
		RightUp = new Point(x, y);
		RightDown = new Point(x, y);
	}
	
	public Integer getWidth()
	{
		return RightUp.getX() - LeftUp.getX();
	}
	
	public Integer getHeight()
	{
		return RightDown.getY() - RightUp.getY();
	}
	
	public Integer getPositionX()
	{
		return LeftUp.getX();
	}
	
	public Integer getPositionY()
	{
		return LeftUp.getY();
	}
	
	
	
	
/*	public void CreationChangeEnd(Integer x, Integer y)
	{
		Integer tmpWidth = x - getPositionX();
		Integer tmpHeight = y - getPositionY();
		
		LeftLeg.setBeginX(x - tmpWidth*5/6);
		LeftLeg.setBeginY(y);
		
		RightLeg.setBeginX(x - tmpWidth*1/6);
		RightLeg.setBeginY(y);
		
		LeftLeg.setEndX(x - tmpWidth/2);
		LeftLeg.setEndY(y - tmpHeight/3);
		
		RightLeg.setEndX(x - tmpWidth/2);
		RightLeg.setEndY(y - tmpHeight/3);
		
		Torso.setBeginX(x - tmpWidth/2);
		Torso.setBeginY(y - tmpHeight/3);
		
		Torso.setEndX(x - tmpWidth/2);
		Torso.setEndY(y - tmpHeight/3);
		
		Head.setFromPoint(new Point(1, 1));
		Head.setToPoint(new Point(getPositionX() + tmpWidth*5/6, getPositionY() + tmpHeight*2/6));
		
		Name.setPosition(new Point(x, y));
	}
	*/

	public Point getLeftUp()
	{
		return LeftUp;
	}

	public Point getLeftDown()
	{
		return LeftDown;
	}

	public Point getRightUp()
	{
		return RightUp;
	}

	public Point getRightDown()
	{
		return RightDown;
	}

	@Override
	public void Draw(Graphics g, PaintObjects po)
	{
		// TODO Auto-generated method stub
		po.DrawBorderAreaUses(g, this);
	}
	
	public void DrawSelection(Graphics g, PaintObjects po)
	{
		// TODO Auto-generated method stub
		po.DrawBorderAreaUsesSelection(g, this);
	}


	public Text getName()
	{
		return Name;
	}

	public void setName(Text name)
	{
		Name = name;
	}

	

	@Override
	public Boolean PointCollision(Integer x, Integer y)
	{
		// TODO Auto-generated method stub
		return super.PointCollision(x, y);
	}

	/*@Override
	public void Print()
	{
		// TODO Auto-generated method stub
		System.out.println("Aktor:  " +
				"Lewa stopa " + LeftLeg.getBeginX() + " " + LeftLeg.getBeginY() + 
				"\nPrawa stopa " + RightLeg.getBeginX() + " " + RightLeg.getBeginY() +
				"\nPepek " + Torso.getBeginX() + " " + Torso.getBeginY() +
				"\nSzyjka " + Torso.getEndX() + " " + Torso.getEndY() +
				"\nGlowa1 " + Head.getFromPoint().getX() + " " + Head.getFromPoint().getY() +
				"\nGlowa2 " + Head.getToPoint().getX() + " " + Head.getToPoint().getY() 
				
				);
	}
*/
	@Override
	public void SetSize(Integer w, Integer h)
	{
		//Integer tmpWidth = x - getPositionX();
		//Integer tmpHeight = y - getPositionY();
		
		
		LeftDown.MoveTo(getPositionX(), getPositionY()+h);
		RightUp.MoveTo(getPositionX()+w, getPositionY());
		RightDown.MoveTo(getPositionX() + w, getPositionY() + h);

		
		Name.MoveTo(getPositionX() + w/2, getPositionY() + 15);
		
		//Name.setPosition(new Point(getPositionX() + w/2-Name.getCaption().length() *3, getPositionY() + h+20*(new Double(getHeight().doubleValue()/120.0).intValue())));
		
		//Integer a = 20*(((getHeight().doubleValue()/70.0)).intValue();
		//Integer b = 20*(new Double(getHeight().doubleValue()/70.0).intValue());
		
	}

	@Override
	public void SetTextSize(Integer size)
	{
		// TODO Auto-generated method stub
		Name.setTextSize(size);
	}

	@Override
	public String ToDatabase()
	{
		// TODO Auto-generated method stub
		return super.ToDatabase();
	}

	@Override
	public Boolean Selection(Integer selLeft, Integer selRight, Integer selUp,
			Integer selBottom)
	{
		ArrayList<Point> allPoints = new ArrayList<Point>();
		allPoints.add(LeftUp);
		allPoints.add(RightUp);
		allPoints.add(RightDown);
		allPoints.add(LeftDown);
		allPoints.add(LeftUp);
		
		
		for (int i = 0; i < 4; ++i)
		{
			if ((new Line(allPoints.get(i).getX(), allPoints.get(i).getY(), allPoints.get(i+1).getX(), allPoints.get(i+1).getY()).Selection(selLeft, selRight, selUp, selBottom)) == true)
				return true;;
		}
		return false;
	}

	@Override
	public void MoveByVector(Integer vx, Integer vy)
	{
		Name.MoveByVector(vx, vy);
		LeftUp.MoveByVector(vx, vy);
		LeftDown.MoveByVector(vx, vy);
		RightUp.MoveByVector(vx, vy);
		RightDown.MoveByVector(vx, vy);
	}
	
	
	
}
